package com.qnw.CardGroupManagement.adapter;

import android.app.*;
import android.content.*;
import android.support.v7.widget.*;
import android.view.*;
import android.widget.*;
import com.qnw.CardGroupManagement.*;
import com.ygo.feihua.*;
import java.util.*;
import com.qnw.CardGroupManagement.bean.*;

public class DeckMessageAdapter extends RecyclerView.Adapter<DeckMessageAdapter.ViewHolder> 
{
	private final int TYPE_LIN=0;
	private final int TYPE_CARD=1;
	
	private Context context;
	private List<DeckCard> data;
	Gongju gj;
	int pmk;

	@Override
	public int getItemViewType(int position) {
		if(position!=data.size()-1&&data.get(position).getType()!=data.get(position+1).getType()){
			return TYPE_LIN;
		}else{
			return TYPE_CARD;
		}
	}

	
	
	public DeckMessageAdapter(Context context,List<DeckCard> data){
		this.context=context;
		this.data=data;
		gj=Gongju.getdx(context);

		Activity a=(Activity)context;
		Display display = a.getWindowManager().getDefaultDisplay();
		pmk = display.getWidth();
	}

	public void sx() {
		notifyDataSetChanged();
		// TODO: Implement this method
	}
	
	@Override
	public DeckMessageAdapter.ViewHolder onCreateViewHolder(ViewGroup p1, int p2) {
		View v;
		int type=getItemViewType(p2);
		if(type==TYPE_CARD){
		v=LayoutInflater.from(p1.getContext()).inflate(R.layout.item_kz,p1,false);
		}else{
			v=LayoutInflater.from(p1.getContext()).inflate(R.layout.item_deck_lin,p1,false);
		}
		// TODO: Implement this method
		return new ViewHolder(v,type);
	}

	@Override
	public void onBindViewHolder(DeckMessageAdapter.ViewHolder vh, int position) {
		
		if(getItemViewType(position)==TYPE_CARD){
		Gongju.setKt(context,vh.kz_kt,data.get(position).getCard().getId());
		}
		// TODO: Implement this method
	}

	@Override
	public int getItemCount() {
		// TODO: Implement this method
		return data.size();
	}
	
	
	class ViewHolder extends RecyclerView.ViewHolder{
		
		ImageView kz_kt;
		
		public ViewHolder(View v,int type){
			super(v);
			if(type==TYPE_CARD){
			kz_kt=(ImageView) v.findViewById(R.id.kz_kt);
			}
		}
	}
	
	
	
}
